﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Visual_CRUD_User_AddUser : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        verificaUser();
    }
    protected void verificaUser()
    {
        VSDBM.Code.dto.User usuariologado = (VSDBM.Code.dto.User)HttpContext.Current.Session["usuariologado"];
        if (!(usuariologado.acessgroup == 1))
        {
            HttpContext.Current.Session["exception"] = "You are not authorized!";
            Response.Redirect("~/Visual/Errors/error.aspx");
        }
    }
    protected void btnSave_Click(object sender, ImageClickEventArgs e)
    {
        VSDBM.Code.dto.User usuario = new VSDBM.Code.dto.User(0, tbname.Text, tbemail.Text, tblogin.Text, VSDBM.Code.functions.Encryption.CalculateMD5Hash(tbpassword.Text), Convert.ToInt32(ddacessgroup.SelectedValue), 1);
        string resp = VSDBM.Code.dao.UserDAO.add(usuario);

        if (resp == "Cadastrado com sucesso!")
        {
            Response.Redirect("ListUser.aspx");
        }
        else
        {
            lbmensagem.Text = resp;
        }
    }
}